﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PDX
{
    /// <summary>
    /// A form that allows a user to view and edit multiple properties.
    /// </summary>
    public class DataForm : Control
    {
        static DataForm()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(DataForm), new FrameworkPropertyMetadata(typeof(DataForm)));
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="DataForm"/> class.
        /// </summary>
        public DataForm()
        {
            IsTabStop = false;

            Declarations = new List<IDeclarationBuilder>();
        }

        /// <summary>
        /// Gets or sets a collection of <see cref="IDeclarationBuilder"/>s
        /// used to build the form.
        /// </summary>
        /// <value>
        /// The declaration builders.
        /// </value>
        public List<IDeclarationBuilder> Declarations { get; set; }

        /// <summary>
        /// This is for binding purposes only!!
        /// </summary>
        /// <remarks>
        /// TODO change this to a converter?
        /// </remarks>
        public IEnumerable<Declaration> _internalDeclarations
        {
            get
            {
                var target = DataContext;
                if (target == null)
                {
                    yield break;
                }

                foreach (var builder in Declarations)
                {
                    foreach (var declaration in builder.BuildDeclarations(target))
                    {
                        yield return declaration;
                    }
                }
            }
        }
    }
}
